﻿<Window x:Class="Blackbird.Studio.View.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow"
        DataContext="{Binding Source={StaticResource ResourceKey=StaticViewModel}, Path=Instance.MainWindowViewModel}">
    <Window.Resources>
        <Style x:Key="WorkspaceTabItemStyle" TargetType="{x:Type TabItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            <Setter Property="FontWeight" Value="Normal" />
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <DataTemplate x:Key="ClosableTabItemTemplate">
            <DockPanel Width="120">
                <Button Command="{Binding Path=CloseCommand}" Content="X" Cursor="Hand" DockPanel.Dock="Right"
                Focusable="False" FontFamily="Arial" FontSize="9" FontWeight="Bold" Margin="0,1,0,0" Padding="0"
                VerticalContentAlignment="Bottom" Width="16" Height="16" />
                <ContentPresenter Content="{Binding Path=Model.Name}" VerticalAlignment="Center" />
            </DockPanel>
        </DataTemplate>

        <DataTemplate x:Key="WorkspacesTemplate">
            <Border VerticalAlignment="Stretch" Style="{StaticResource MainBorderStyle}">
                <TabControl IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}"
                    ItemTemplate="{StaticResource ClosableTabItemTemplate}" ItemContainerStyle="{StaticResource WorkspaceTabItemStyle}"
                    Margin="6" />
            </Border>
        </DataTemplate>

    </Window.Resources>

    <Grid  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition MaxWidth="200px" />
        </Grid.ColumnDefinitions>
        <DockPanel>
            <DockPanel DockPanel.Dock="Top">
                <Menu>
                    <MenuItem Header="_File">
                        <MenuItem Header="{Binding Path=NewModuleCommand.DisplayName}"
                      Command="{Binding Path=NewModuleCommand.Command}"></MenuItem>
                        <MenuItem Header="{Binding Path=OpenModuleCommand.DisplayName}"
                      Command="{Binding Path=OpenModuleCommand.Command}"></MenuItem>
                        <MenuItem Header="{Binding Path=SaveModuleCommand.DisplayName}"
                      Command="{Binding Path=SaveModuleCommand.Command}"></MenuItem>
                        <MenuItem Header="{Binding Path=SaveModuleAsCommand.DisplayName}"
                      Command="{Binding Path=SaveModuleAsCommand.Command}"></MenuItem>
                        <MenuItem Header="{Binding Path=CloseModuleCommand.DisplayName}"
                      Command="{Binding Path=CloseModuleCommand.Command}"></MenuItem>
                        <Separator />
                        <MenuItem Header="E_xit" Command="{Binding Path=CloseCommand}"></MenuItem>
                    </MenuItem>
                </Menu>
            </DockPanel>
            <Grid Margin="4">
                <!-- Editor Content -->
                <ContentPresenter Content="{Binding Path=Workspaces}" VerticalAlignment="Stretch"
                          HorizontalAlignment="Stretch" ContentTemplate="{StaticResource ResourceKey=WorkspacesTemplate}" />
            </Grid>

        </DockPanel>
        <ListView ItemsSource="{Binding Path=RegisteredCommands}" Grid.Column="1">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Border CornerRadius="4">
                        <Button Content="{Binding Path=DisplayName}" Command="{Binding Path=Command}" Width="180px">

                        </Button>
                    </Border>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Window>